package Demo11;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletRequest;

public class DIYInterceptor extends MethodFilterInterceptor {

    @Override
    //拦截器逻辑
    protected String doIntercept(ActionInvocation actionInvocation) throws Exception {

        HttpServletRequest request=ServletActionContext.getRequest();
        Object obj=request.getSession().getAttribute("username");
        if (obj!=null){
            //放行
            return actionInvocation.invoke();
        }else {
            return  "fail";
        }
    }
}
